package sgpt.util;

import java.util.Map;

import javax.faces.application.Application;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import sgpt.control.Icontrole;

public class tools {
	public static Icontrole getSessionBean(String nome){
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
		return (Icontrole) session.getAttribute(nome);
	}
	
	public static void putSessionBean(String nome,Icontrole bean){
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
		session.setAttribute(nome,bean);
	}

	public static Icontrole getAppBean(String nome){
		FacesContext ctx = FacesContext.getCurrentInstance();
		ExternalContext externalContest = ctx.getExternalContext();
		return (Icontrole) externalContest.getApplicationMap().get(nome);
	}
	
	public static void putAppBean(String nome,Icontrole bean){
		FacesContext ctx = FacesContext.getCurrentInstance();
		ExternalContext externalContest = ctx.getExternalContext();
		externalContest.getApplicationMap().put(nome,bean);
	}
	public static Object getSessionVar(String nome){
		ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
		Map<String, Object> sessionMap = externalContext.getSessionMap();
		return sessionMap.get(nome);
	}
	public static void putSessionVar(String nome,Object value){
		ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
		Map<String, Object> sessionMap = externalContext.getSessionMap();
		sessionMap.put(nome, value);
	}
}
